import * as mixins from '@/utils/mixins';
import * as filters from '@/utils/filters';
import * as constants from "@/utils/constants";
import * as directives from "@/utils/directives";
const functionContext = require.context('@/functions/', true, /\.js$/);
const componentsContext = require.context('@/components/global/', true, /\.vue$/);
export default {
	install(Vue) {
		//全局过滤器
		Object.keys(filters).forEach(key => {
			Vue.filter(key, filters[key])
		})
		//全局常量
		Object.keys(constants).forEach(key => {
			Vue.prototype[key] = constants[key];
		})
		//定义全局指令
		Object.keys(directives).forEach(key => {
			Vue.directive(key, directives[key]);
		})
		//全局事件
		functionContext.keys().forEach((func) => {
			let funcConfig = functionContext(func);
			Object.keys(funcConfig).forEach(key => {
				Vue.prototype[key] = funcConfig[key];
			})
		})
		//全局组件
		componentsContext.keys().forEach((comp) => {
			let compsConfig = componentsContext(comp);
			let compSelf = compsConfig.default || compsConfig;
			if (compSelf && compSelf.name) {
				Vue.component(compSelf.name, compSelf);
			}
		})
		//定义全局混入
		Object.keys(mixins).forEach(key => {
			Vue.mixin(mixins[key]);
		})
	}
};